import axios from 'axios'
import qs from 'qs'
/* import Promise from 'promise-polyfill' */
axios.defaults.timeout = 5000
axios.defaults.withCredentials = true
axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'

/* if (!window.Promise) {
  window.Promise = Promise
} */
export default {
  fetchGet (url, params = {}) {
    return new Promise((resolve, reject) => {
      axios.get(url, params).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  fetchPost (url, params = {}) {
    return new Promise((resolve, reject) => {
      axios.post(url, qs.stringify(params)).then(res => {
       /*  if (res.data.status === 1) {
          console.log('error')
        } else {
          resolve(res.data)
        } */
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  }
}
